import ajax from '@/utils/request'
import { concatUrl } from '@/utils'

type Field = string | object

interface Location {
  userLongitude?: string
  userLatitude?: string
  query?: any
}

interface HomeIndex extends Location { }
interface OftenStore extends Location {
  storeType?: number
}
interface NearStore extends Location { }
interface StoreIndex extends Location { }
interface StoreGoods {
  serviceId?: number | string
}
interface AllStore {
  userLongitude?: string
  userLatitude?: string
  keyword?: any
  query?: any
}

// 开通城市
export function openCities(data?, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl(`${PUB_API_BASH_URL}/v1/area-city/open-list`, fields),
    data
  })
}
// 平台首页接口
export function getHomeIndex(data: HomeIndex, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/home/index', fields),
    data
  })
}

// 常用门店列表
export function oftenStore(data: OftenStore, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/store/common-list', fields),
    data
  })
}

// 附近门店列表
export function nearStore(data: NearStore, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/store/near-list', fields),
    data
  })
}
const storeFields: string = 'storeCode,storeName,vendorCode,vendorName,phone,address,cityName,cityCode,longitude,latitude,isOpen,isInService,distance,logo,isNew,status,statusLabel'
// 门店首页接口
export function storeIndex(data?: StoreIndex, fields: Field = { fields: storeFields }) {
  return ajax({
    url: concatUrl('/v1/store/index', fields),
    data
  })
}

// 门店商品接口
export function storeGoods(data?: StoreGoods, fields: Field = { fields: 'categoryList,productList' }) {
  return ajax({
    url: concatUrl('/v1/store/product', fields),
    data
  })
}

// 门店信息
export function storeInfo(data?, fields: Field = { fields: '*' }) {
  console.log('data----ifHandleError', data)
  return ajax({
    url: concatUrl('/v1/store/store-info', fields),
    data,
    inHandleError: data.inHandleError
  })
}

// 接入商门店
export function allStore(data: AllStore, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/store/all-store', fields),
    data
  })
}

// 保险按钮显示
export function controlInsuranceBtn(data?, fields: Field = { fields: 'show' }) {
  return ajax({
    url: concatUrl('/v1/store/insurance', fields),
    data
  })
}

// 获取首页配置
export function getConfig(data?, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/page/page/get-config', fields),
    data
  })
}

// 获取首页结构
export function getStructure(data?) {
  return ajax({
    url: concatUrl('/v1/home-page/home-page/get-structure'),
    data
  })
}

// 获取内容
export function getContent(data?) {
  return ajax({
    // url: concatUrl('/v1/home-page/home-page/get-content'),
    url: concatUrl('/v1/home-page/home-page/get-platform-content'),
    data
  })
}

// 基础服务项目商品列表
export function getServiceGoods(data?, fields: Field = { fields: '*,goods.*' }) {
  return ajax({
    url: concatUrl('/v1/service-goods/index', fields),
    data
  })
}

// 首页前端服务列表
export function getFrontServiceGoods(data?) {
  return ajax({
    url: concatUrl('/v1/front-service-goods/list'),
    data
  })
}

// 首页弹窗信息
export function getHomePopup(data?, fields: Field = { fields: 'id,createdAt,updatedAt,name,keyword,openTime,linkType,linkContent,startTime,endTime,isOnline,popImage' }) {
  return ajax({
    url: concatUrl('/v1/popup/home-popup/index', fields),
  })
}
// 门店详情
export function getStoreInfo(data?, fields: Field = { fields: 'brandLogo,carLicense,userName,createdAt,commentContent,goodsGrade,attitudeGrade,efficiencyGrade,qualityGrade,coverImgUrl,carBrandName' }) {
  return ajax({
    url: concatUrl('/v1/store/store-info/index', fields),
    data
  })
}


// 获取可下单门店 列表
export function getCanOrderStoreList(data: NearStore, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v2/store/get-can-order-list', fields),
    data
  })
}

// 获取可预约门店 列表
export function getCanBookingStoreList(data: NearStore, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v2/store/get-can-booking-list', fields),
    data
  })
}

// 根据城市编码获取城市名称
export function getViewByCityCode(data, fields: string | object = { fields: 'adCode,name' }) {
  return ajax({
    url: concatUrl('/v2/ad-area/view-by-ad-code', fields),
    data,
    method: 'GET'
  })
}

// 根据城市编码获取默认区域信息
export function getDefaultAreaInfo(data) {
  return ajax({
    url: concatUrl('/v2/ad-area/get-default-ad'),
    data,
    method: 'GET'
  })
}

// 根据经纬度获取位置
export function getMapReGeo(data) {
  return ajax({
    url: concatUrl('/v2/ad-area/get-map-re-geo'),
    data,
    method: 'GET'
  })
}
// 根据地址获取经纬度
export function getMapGeo(data) {
  return ajax({
    url: concatUrl('/v2/ad-area/get-map-geo'),
    data,
    method: 'GET'
  })
}
